#include "Unit.h"

Unit::Unit(const Amount& factor, const string& str)
:factorToUnit_m(factor), unitName_m(str)
{
}

Amount Unit::convertToUnit(const Amount& length) const
{
	return length*factorToUnit_m;
}

Amount Unit::convertFromUnit(const Amount& length) const
{
	return length/factorToUnit_m;
}

Amount Unit::calremainder(const Amount& length) const
{
	return length%factorToUnit_m;
}

string Unit::getUnitName() const
{
	return unitName_m;
}


bool cmpUnit(const Unit* lh, const Unit* rh)
{
	return lh->factorToUnit_m > rh->factorToUnit_m;
}
void Unit::insert(const Unit* pElement, UnitVector* unitVector)
{
	Unit::UnitVector::iterator pos =lower_bound(unitVector->begin(),unitVector->end(),pElement, cmpUnit);
	unitVector->insert(pos, pElement);
	return;
}










